﻿using System;
using Dgg.LearnYourTools.NUnit.C_Assertions.Support;
using NUnit.Framework;

namespace Dgg.LearnYourTools.NUnit.C_Assertions.a_Exceptions
{
	[TestFixture]
	public class _019_Attributes
	{
		[Test, ExpectedException(typeof(ArgumentOutOfRangeException))]
		public void RangeCtor_UnorderedBounds_Exception_SimpleAttributeHandling()
		{
			new Range<int>(5, 1);
		}

		[Test, ExpectedException(typeof(ArgumentOutOfRangeException), ExpectedMessage = "-5", MatchType = MessageMatch.Contains)]
		public void RangeCtor_UnorderedBounds_Exception_MessageAttributeHandling()
		{
			new Range<int>(-1, -5);
		}

		[Test, ExpectedException(Handler = "RangeCtor_ExceptionHandler")]
		public void RangeCtor_UnorderedBounds_Exception_AttributeWithHandler()
		{
			new Range<int>(-1, -5);
		}

		internal void RangeCtor_ExceptionHandler(Exception e)
		{
			ArgumentOutOfRangeException ex = (ArgumentOutOfRangeException)e;
			Assert.That(ex.ParamName, Is.EqualTo("upperBound"));
			Assert.That(ex.ActualValue, Is.EqualTo(-5));
			Assert.That(ex.Message, Is.StringContaining("-5"));
		}
	}
}
